home *** CD-ROM | disk | FTP | other *** search
/ The Programmer Disk / The Programmer Disk (Microforum).iso / xpro / pascal3 / pro9 / cpexec.asm < prev    next >
Assembly Source File  |  1988-04-17  |  3KB  |  111 lines

  1.         IFDEF  M286                ; "/DM286" on the MASM command line will
  2.         .286                       ; assemble for 80186/286/386 processors
  3.         ELSE
  4.         .8086
  5.         ENDIF
  6.  
  7. DATA    SEGMENT WORD PUBLIC
  8.         EXTRN  WindMin: WORD       ; Pascal variables
  9.         EXTRN  WindMax: WORD
  10.         EXTRN  TextAttr: WORD      ; Actually a byte but can't PUSH byte
  11.         EXTRN  SPTable: WORD
  12.         EXTRN  CurrentTask: WORD
  13.         EXTRN  ActiveTasks:WORD
  14.  
  15.         EXTRN  WhereXY:FAR         ; Pascal routines
  16.         EXTRN  GoToXYAbs:FAR
  17.         EXTRN  CursorTypeSL:FAR
  18.         EXTRN  SetCursorSize:FAR
  19. DATA    ENDS
  20.  
  21. CODE    SEGMENT BYTE PUBLIC
  22.  
  23.         ASSUME CS:CODE, DS:DATA
  24.  
  25.         PUBLIC TaskSwitch
  26.  
  27. TaskSwitch     PROC FAR            ; procedure TaskSwitch;
  28.  
  29.         PUSHF                      ; Save registers
  30.         PUSH   DS
  31.         IFDEF  M286
  32.         PUSHA                      ; 80186/80286/386 only
  33.         ELSE
  34.         PUSH   AX                  ; PUSHA equivalent for 8086/88
  35.         PUSH   CX
  36.         PUSH   DX
  37.         PUSH   BX
  38.         PUSH   SP
  39.         PUSH   BP
  40.         PUSH   SI
  41.         PUSH   DI
  42.         ENDIF
  43.  
  44.         PUSH   ES
  45.         CALL   CursorTypeSL        ; Get current cursor type
  46.         PUSH   AX
  47.         CALL   WhereXY             ; Get current cursor position
  48.         PUSH   AX
  49.         PUSH   WindMin
  50.         PUSH   WindMax
  51.         PUSH   TextAttr
  52.  
  53.         LEA    DI,SPTable          ; DI := SPTable
  54.         MOV    BX,[CurrentTask]    ; BX := current task
  55.         MOV    CL,2                ; 4 bytes per entry
  56.         SHL    BX,CL
  57.         MOV    [BX+DI],SP          ; Save current stack pointer
  58.         MOV    [BX+DI+2],SS
  59.         LEA    SI,ActiveTasks
  60.         SHR    BX,CL               ; Restore BX
  61. FINDNEXT:
  62.         INC    BX                  ; Next task number
  63.         AND    BX,0FH              ; Maximum of 16 tasks
  64.         CMP    BYTE PTR [BX+SI],0  ; Task installed?
  65.         JZ     FINDNEXT            ; No, keep incrementing BX
  66.  
  67.         MOV    [CurrentTask],BX    ; Save new task number
  68.         SHL    BX,CL               ; 4 bytes per entry
  69.         CLI                        ; No interrupts while we ...
  70.         MOV    SP,[BX+DI]          ; ... load stack pointer with new task
  71.         MOV    SS,[BX+DI+2]
  72.         STI                        ; Interrupts ok now
  73.  
  74.         POP    TextAttr            ; Restore text attributes
  75.         POP    WindMax             ; Restore window parameters
  76.         POP    WindMin
  77.         POP    DX                  ; Restore cursor position
  78.         PUSH   DX
  79.         MOV    AL,DH
  80.         PUSH   AX
  81.         CALL   GoToXYAbs
  82.         POP    DX                  ; Restore cursor type
  83.         MOV    AL,DH
  84.         PUSH   AX
  85.         PUSH   DX
  86.         CALL   SetCursorSize
  87.         POP    ES                  ; Restore registers
  88.  
  89.         IFDEF  M286
  90.         POPA                       ; 80186/286/386 only
  91.         ELSE
  92.         POP    DI                  ; POPA equivalent for 8086/88
  93.         POP    SI
  94.         POP    BP
  95.         POP    BX                  ; Not a typo, SP is discarded
  96.         POP    BX
  97.         POP    DX
  98.         POP    CX
  99.         POP    AX
  100.         ENDIF
  101.  
  102.         POP    DS
  103.         POPF
  104.         RET                        ; Activate next task
  105.  
  106. TaskSwitch     ENDP
  107.  
  108. CODE    ENDS
  109.  
  110.         END
  111.